package com.example.dw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.dw.entity.UserFavoriteCourse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户收藏课程Mapper接口
 * @author system
 * @since 2024-01-01
 */
@Mapper
public interface UserFavoriteCourseMapper extends BaseMapper<UserFavoriteCourse> {

    /**
     * 检查用户是否收藏了某个课程
     */
    @Select("SELECT * FROM user_favorite_course " +
            "WHERE userid = #{userid} AND courseid = #{courseid} " +
            "ORDER BY user_course_id DESC LIMIT 1")
    UserFavoriteCourse checkFavorite(@Param("userid") Integer userid,
                                     @Param("courseid") Integer courseid);

    /**
     * 更新收藏状态
     */
    @Update("UPDATE user_favorite_course SET status = #{status} " +
            "WHERE userid = #{userid} AND courseid = #{courseid}")
    int updateFavoriteStatus(@Param("userid") Integer userid,
                           @Param("courseid") Integer courseid,
                           @Param("status") Integer status);

    /**
     * 插入新的收藏记录
     */
    @Update("INSERT INTO user_favorite_course (userid, courseid, status) " +
            "VALUES (#{userid}, #{courseid}, #{status})")
    int insertFavorite(@Param("userid") Integer userid,
                      @Param("courseid") Integer courseid,
                      @Param("status") Integer status);
} 